﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Arizu.Repository;
using System.Web.SessionState;
using System.Data;
using Arizu.Entity;

namespace AiRiZu.User.handler
{
    public class SendMsg : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            AirizuUser userDao = AirizuUser.CreateInstance();
            int userId = -1;
            if (context.Session["logId"] != null && context.Session["roomId"] != null)
            {
                userId = int.Parse(context.Session["logId"].ToString());

                AirizuRoom airizuRoom = AirizuRoom.CreateInstance();
                DataTable dt1 = airizuRoom.GetRoom(long.Parse(context.Session["roomId"].ToString()));
                long ownerId = long.Parse(dt1.Rows[0]["OwnerID"].ToString());

                MessageEntity message = new MessageEntity();

                message.Reciver = ownerId;
                message.Sender = userId;
                message.Message = context.Request.Params["offer_message"];
                message.State = (int)MessageState.Unread;
                message.Type = (int)MessageType.User;

                AirizuMessage AirizuMessage = AirizuMessage.CreateInstance();
                AirizuMessage.InsertMessage(message);

                context.Response.Redirect("../Contact.aspx");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
